;define(function (require, exports, module) {
    'use strict';
    /*这是支持的整个dom下输入框的验证*/
    var validateInput = function(dom){
        if (!dom) {
            dom = document;
        }
        var _d = $(dom);
        var ins = _d.find("input,textarea,select");
        var promptString = "";
        for(var i=0;i<ins.length;i++){
            var _t = $(ins[i]);
            var isNull = parseInt(_t.attr("isNUll"));//1表示非空 0表示可为空
            var minLength = parseInt(_t.attr("minLength"));
            var maxLength = parseInt(_t.attr("maxLength"));
            var description = _t.attr("description");
            var codeName = _t.attr("codeName");
            var value = $.trim(_t.val());
            if(isNull == 1){
                if(value.length == 0){
                    promptString = "请输入"+codeName;
                    return promptString;
                }
                if(value.length<minLength || value.length>maxLength){
                    promptString = description == undefined?codeName+"允许的字段长度为"+minLength+"~"+maxLength:description; 
                    return promptString;
                }
            }else if(isNull == 0){
                if(value.length>maxLength){
                    promptString = description == undefined?codeName+"的长度不能超过"+maxLength:description;
                    return promptString;
                }
            }
        }
        return promptString;
    };
    /*是否是合法的标识符(以字母开头，字母、数字、下划线的组合)*/
    var isIdentifier = function(obj,message){
        var _d = $(obj);
        var promptString = "";
        if($.trim(_d.val()).length != 0){
            var strCheck=/^[a-zA-Z]+(_{0,1}[a-zA-Z0-9])*$/;
            if (!strCheck.exec(_d.val())){
                promptString = message == null ?'标识符格式不正确.':message;
            }
        }else{
            promptString = "长度不能为空！";
        }
        return promptString;
    };
    /*判断两次输入的密码是否正确*/
    var isEquals = function(obj1,obj2,message){
        var promptString =  "";
        var value1 = $.trim($(obj1).val());
        var value2 = $.trim($(obj2).val());
        if(value1.length != 0 || value2.length != 0){
            if(value1 != value2){
                promptString = message == null?"两次输入的密码不一致！":message;
            }
        }else{
            promptString = "密码不能为空！";
        }
        return promptString;
    };
    /*是否是合法的E_mail地址(以字母开头，字母、数字、下划线的组合，中间必须有一个“@”)*/
    var isEmail = function(obj,message){
        var value = $.trim($(obj).val());
        var promptString = "";
        if(value.length != 0){
            var strCheck=/^\S+@\S+\.\S+$/;
            if (!strCheck.exec(value))    {
                promptString = message == null ? '电子邮件格式不正确.':message;
            }
        }else{
            promptString = "邮箱不能为空！";
        }
        return promptString;
    };
    /*判断身份证是否合法*/
    var isIdCard = function(obj,message){
        var idcard = $.trim($(obj).val());
        var promptString = "";
        var partten = /^[\d]{6}((19[\d]{2})|(200[0-8]))((0[1-9])|(1[0-2]))((0[1-9])|([12][\d])|(3[01]))[\d]{3}[0-9xX]$/
        var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
        if(!idcard || !partten.test(idcard)){
            promptString = message == null?"请输入合法的身份证号！":message;
        }
        else if(!city[idcard.substr(0,2)]){
        	promptString = message == null?"请输入合法的身份证号！":message;
        }
        else{
            //18位身份证需要验证最后一位校验位
//          if(idcard.length == 18){
//              idcard = idcard.split('');
//              //∑(ai×Wi)(mod 11)
//              //加权因子
//              var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
//              //校验位
//              var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
//              var sum = 0;
//              var ai = 0;
//              var wi = 0;
//              for (var i = 0; i < 17; i++)
//              {
//                  ai = idcard[i];
//                  wi = factor[i];
//                  sum += ai * wi;
//              }
//              var last = parity[sum % 11];
//              if(parity[sum % 11] != idcard[17]){
//                  var tip = "校验位错误";
//                  promptString = message == null?"请输入合法的身份证号！":message;
//              }
//          }
        }
        return promptString;
    };
    /*手机号检测*/
    var isPhone = function(obj,message){
        var value = $.trim($(obj).val());
        var strCheck= /^1[3|4|5|7|8][0-9]\d{8}$/;
        var isNull = parseInt($(obj).attr("isNull"));
        var promptString = "";
        if(value.length != 0){
            if(strCheck.test(value) === false){
                promptString = message == null?"请输入正确的手机号码":message;
            }
        }else{
            if(isNull == 1){
                promptString ="手机号码不能为空！";
            }
        }
        return promptString;
    };
    /*验证单个的输入框*/
    var checkInput = function(obj,message){
        var _t = $(obj);
        var promptString = "";
        var isNull = _t.attr("isNUll");//1表示非空 0表示可为空
        var minLength = _t.attr("minLength");
        var maxLength = _t.attr("maxLength");
        var description = _t.attr("description");
        var value = $.trim(_t.val());
            if(isNull == 1){
                if(value.length<minLength || value.length>maxLength){
                    promptString = description == null?"该字段允许的字段长度为"+minLength+"~"+maxLength:description; 
                    return promptString;
                }
            }else{
                if(value.length>maxLength){
                    promptString = description == null?"该字段的长度不能超过"+maxLength:description;
                    return promptString;
                }
            }
            return promptString;
    };
    var validateFileType = function(obj,fileType){
         //获取欲上传的文件路径
        var filepath = $(obj).val(); 
        //为了避免转义反斜杠出问题，这里将对其进行转换
        var re = /(\\+)/g; 
        var filename=filepath.replace(re,"#");
        if(filename.length > 100){
            return "对不起！文件名过长！";
        }
        //对路径字符串进行剪切截取
        var one=filename.split("#");
        //获取数组中最后一个，即文件名
        var two=one[one.length-1];
        //再对文件名进行截取，以取得后缀名
        var three=two.split(".");
         //获取截取的最后一个字符串，即为后缀名
        var last=three[three.length-1];

        //添加需要判断的后缀名类型
        var tp = fileType == undefined?"jpg,gif,bmp,JPG,GIF,BMP,png":fileType;
        //返回符合条件的后缀名在字符串中的位置
        var rs=tp.indexOf(last);
        //如果返回的结果大于或等于0，说明包含允许上传的文件类型
        if(rs!=-1){
            return "";
        }else{ 
            return "抱歉！暂时不支持此种类型文件的上传！";
        }
    };
    return {
        validateInput:validateInput,
        isIdentifier:isIdentifier,
        isEquals:isEquals,
        isEmail:isEmail,
        isIdCard:isIdCard,
        isPhone:isPhone,
        checkInput:checkInput,
        validateFileType:validateFileType
    };
});